import { Comment, CommentTag, CommentPageResult } from '@/types/comment';
import { AIModel, ModelComparison } from '@/types/model';

// 模拟评论标签数据
export const commentTags: CommentTag[] = [
  {
    id: 't1',
    name: '物流快',
    color: '#52c41a',
    description: '评论中提到物流速度快',
    category: 'feature',
    count: 1254
  },
  {
    id: 't2',
    name: '质量差',
    color: '#f5222d',
    description: '评论中提到产品质量问题',
    category: 'issue',
    count: 842
  },
  {
    id: 't3',
    name: '态度好',
    color: '#1890ff',
    description: '评论中提到客服态度好',
    category: 'feature',
    count: 967
  },
  {
    id: 't4',
    name: '价格高',
    color: '#fa8c16',
    description: '评论中认为价格偏高',
    category: 'issue',
    count: 632
  },
  {
    id: 't5',
    name: '推荐购买',
    color: '#722ed1',
    description: '评论明确推荐购买',
    category: 'sentiment',
    count: 1589
  },
  {
    id: 't6',
    name: '包装精美',
    color: '#ff4d4f',
    description: '评论中提到包装精致',
    category: 'feature',
    count: 753
  },
  {
    id: 't7',
    name: '续航差',
    color: '#ffa94d',
    description: '评论中提到续航能力不足',
    category: 'issue',
    count: 521
  }
];

// 模拟AI模型数据
export const aiModels: AIModel[] = [
  {
    id: 'm1',
    name: '基线模型',
    description: '基础机器学习模型，适用于简单场景',
    accuracy: 0.78,
    speed: 120,
    supportBatch: true,
    isDefault: false,
    createdAt: '2023-01-15',
    updatedAt: '2023-06-20'
  },
  {
    id: 'm2',
    name: 'BERT模型',
    description: '基于BERT的预训练模型，语义理解能力强',
    accuracy: 0.89,
    speed: 45,
    supportBatch: true,
    isDefault: true,
    createdAt: '2023-03-10',
    updatedAt: '2023-07-15'
  },
  {
    id: 'm3',
    name: 'DeepSeek模型',
    description: '基于DeepSeek的大语言模型，综合性能优秀',
    accuracy: 0.93,
    speed: 30,
    supportBatch: true,
    isDefault: false,
    createdAt: '2023-05-20',
    updatedAt: '2023-08-05'
  },
  {
    id: 'm4',
    name: 'LLaMA模型',
    description: '基于LLaMA的开源模型，适合定制化场景',
    accuracy: 0.91,
    speed: 38,
    supportBatch: false,
    isDefault: false,
    createdAt: '2023-06-30',
    updatedAt: '2023-08-20'
  }
];

// 辅助函数：获取随机标签ID
const getRandomTagId = (): string => {
  if (commentTags.length === 0) {
    return 'default-tag';
  }
  const randomIndex = Math.floor(Math.random() * commentTags.length);
  return commentTags[randomIndex].id;
};

// 生成模拟评论数据
const generateMockComments = (): Comment[] => {
  const comments: Comment[] = [];
  const products = ['智能手机A', '笔记本电脑B', '无线耳机C', '智能手表D', '平板电脑E', '智能音箱F'];
  const sentiments: ('positive' | 'negative' | 'neutral')[] = ['positive', 'negative', 'neutral'];
  const contents = [
    '产品非常不错，超出预期，值得购买！',
    '一般般，没有达到宣传的效果，不太推荐。',
    '还行，符合这个价位的品质，中规中矩。',
    '使用体验很好，下次还会回购。',
    '质量有问题，联系客服处理了但不太满意。',
    '包装很用心，物流也快，点赞！',
    '价格有点高，但品质确实不错，值得投资。',
    '功能齐全，操作简单，很适合新手使用。'
  ];

  for (let i = 1; i <= 100; i++) {
    // 生成1-3个随机标签ID
    const tagOptions: string[] = [];
    const tagCount = Math.floor(Math.random() * 3) + 1;
    for (let j = 0; j < tagCount; j++) {
      tagOptions.push(getRandomTagId());
    }

    // 去重标签ID
    const tagSet = new Set<string>(tagOptions);
    const uniqueTagIds: string[] = Array.from(tagSet);

    // 查找标签详情
    const tagDetails = uniqueTagIds
      .map(tagId => commentTags.find(t => t.id === tagId))
      .filter((tag): tag is CommentTag => !!tag);

    // 随机选择评论内容
    const contentIndex = Math.floor(Math.random() * contents.length);

    comments.push({
      id: `c${i}`,
      content: `${contents[contentIndex]}（这是第${i}条评论）`,
      productId: `p${Math.floor(i % 6) + 1}`,
      productName: products[Math.floor(i % 6)],
      username: `user${i}`,
      createdAt: new Date(Date.now() - Math.floor(Math.random() * 90) * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
      tags: tagDetails,
      tagIds: uniqueTagIds,
      sentiment: sentiments[Math.floor(Math.random() * 3)],
      predictionResult: {
        modelId: aiModels[Math.floor(Math.random() * aiModels.length)].id,
        confidence: Math.round((0.7 + Math.random() * 0.25) * 100) / 100,
        predictedAt: new Date(Date.now() - Math.floor(Math.random() * 14) * 24 * 60 * 60 * 1000).toISOString().split('T')[0]
      }
    });
  }

  return comments;
};

// 模拟评论分页数据
export const getMockComments = (params: {page: number, pageSize: number}): CommentPageResult => {
  const allComments = generateMockComments();
  const { page, pageSize } = params;
  const startIndex = (page - 1) * pageSize;
  const endIndex = startIndex + pageSize;

  return {
    list: allComments.slice(startIndex, endIndex),
    total: allComments.length,
    page,
    pageSize,
    totalPages: Math.ceil(allComments.length / pageSize)
  };
};

// 模拟模型对比数据
export const modelComparisons: ModelComparison[] = [
  {
    date: '2023-08-01',
    models: {
      'm1': { accuracy: 0.76, precision: 0.75, recall: 0.77, f1Score: 0.76, processingTime: 120 },
      'm2': { accuracy: 0.88, precision: 0.87, recall: 0.89, f1Score: 0.88, processingTime: 48 },
      'm3': { accuracy: 0.92, precision: 0.91, recall: 0.93, f1Score: 0.92, processingTime: 32 },
      'm4': { accuracy: 0.89, precision: 0.88, recall: 0.90, f1Score: 0.89, processingTime: 39 }
    }
  },
  {
    date: '2023-08-08',
    models: {
      'm1': { accuracy: 0.77, precision: 0.76, recall: 0.78, f1Score: 0.77, processingTime: 118 },
      'm2': { accuracy: 0.89, precision: 0.88, recall: 0.90, f1Score: 0.89, processingTime: 46 },
      'm3': { accuracy: 0.93, precision: 0.92, recall: 0.94, f1Score: 0.93, processingTime: 31 },
      'm4': { accuracy: 0.90, precision: 0.89, recall: 0.91, f1Score: 0.90, processingTime: 37 }
    }
  },
  {
    date: '2023-08-15',
    models: {
      'm1': { accuracy: 0.78, precision: 0.77, recall: 0.79, f1Score: 0.78, processingTime: 122 },
      'm2': { accuracy: 0.89, precision: 0.88, recall: 0.90, f1Score: 0.89, processingTime: 47 },
      'm3': { accuracy: 0.94, precision: 0.93, recall: 0.95, f1Score: 0.94, processingTime: 30 },
      'm4': { accuracy: 0.91, precision: 0.90, recall: 0.92, f1Score: 0.91, processingTime: 38 }
    }
  },
  {
    date: '2023-08-22',
    models: {
      'm1': { accuracy: 0.78, precision: 0.76, recall: 0.80, f1Score: 0.78, processingTime: 121 },
      'm2': { accuracy: 0.90, precision: 0.89, recall: 0.91, f1Score: 0.90, processingTime: 45 },
      'm3': { accuracy: 0.95, precision: 0.94, recall: 0.96, f1Score: 0.95, processingTime: 29 },
      'm4': { accuracy: 0.92, precision: 0.91, recall: 0.93, f1Score: 0.92, processingTime: 36 }
    }
  }
];

// 模拟用户数据
export const mockUsers = {
  admin: {
    id: 'u1',
    username: 'admin',
    role: 'admin',
    avatar: 'https://picsum.photos/id/1/200',
    permissions: ['all']
  },
  user: {
    id: 'u2',
    username: 'user',
    role: 'user',
    avatar: 'https://picsum.photos/id/2/200',
    permissions: ['view', 'predict']
  },
  analyst: {
    id: 'u3',
    username: 'analyst',
    role: 'analyst',
    avatar: 'https://picsum.photos/id/3/200',
    permissions: ['view', 'predict', 'export']
  }
};

// 模拟仪表盘统计数据
export const mockDashboardStats = {
  totalComments: 12580,
  positiveRatio: 0.62,
  negativeRatio: 0.23,
  processedRatio: 0.87,
  dailyTrend: [
    { date: '2023-08-16', count: 320 },
    { date: '2023-08-17', count: 280 },
    { date: '2023-08-18', count: 350 },
    { date: '2023-08-19', count: 420 },
    { date: '2023-08-20', count: 390 },
    { date: '2023-08-21', count: 310 },
    { date: '2023-08-22', count: 370 }
  ],
  tagDistribution: [
    { tag: '物流快', count: 1254, color: '#52c41a' },
    { tag: '质量差', count: 842, color: '#f5222d' },
    { tag: '态度好', count: 967, color: '#1890ff' },
    { tag: '价格高', count: 632, color: '#fa8c16' },
    { tag: '推荐购买', count: 1589, color: '#722ed1' },
    { tag: '包装精美', count: 753, color: '#ff4d4f' },
    { tag: '续航差', count: 521, color: '#ffa94d' }
  ],
  modelUsage: [
    { model: '基线模型', usage: 1200 },
    { model: 'BERT模型', usage: 5800 },
    { model: 'DeepSeek模型', usage: 3200 },
    { model: 'LLaMA模型', usage: 1500 }
  ]
};

export const mockModels: AIModel[] = [
  {
    id: 'm1',
    name: '基线模型',
    description: '基础机器学习模型，适用于简单场景',
    accuracy: 0.78,
    speed: 120,
    supportBatch: true,
    isDefault: false,
    createdAt: '2023-01-15',
    updatedAt: '2023-06-20'
  },
  {
    id: 'm2',
    name: 'BERT模型',
    description: '基于BERT的预训练模型，语义理解能力强',
    accuracy: 0.89,
    speed: 45,
    supportBatch: true,
    isDefault: true,
    createdAt: '2023-03-10',
    updatedAt: '2023-07-15'
  },
  {
    id: 'm3',
    name: 'DeepSeek模型',
    description: '基于DeepSeek的大语言模型，综合性能优秀',
    accuracy: 0.93,
    speed: 30,
    supportBatch: true,
    isDefault: false,
    createdAt: '2023-05-20',
    updatedAt: '2023-08-05'
  },
  {
    id: 'm4',
    name: 'LLaMA模型',
    description: '基于LLaMA的开源模型，适合定制化场景',
    accuracy: 0.91,
    speed: 38,
    supportBatch: false,
    isDefault: false,
    createdAt: '2023-06-30',
    updatedAt: '2023-08-20'
  }
];

export const mockModelComparisons = [
  { id: '1', name: '对比A', value: 100 },
  { id: '2', name: '对比B', value: 200 },
  { id: '3', name: '对比C', value: 150 }
];

